package com.wframe.project.jnd.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/4/26.
 */
@Controller
@RequestMapping("/error")
public class ErrorController {

    private boolean isMobile(String userAgent) {
        boolean result = false;
        String mobileReg = "^.*(mobile|iphone|android|symbianos|windows\\sphone).*$";
        if (StringUtils.isNotEmpty(userAgent) && userAgent.toLowerCase().matches(mobileReg)) {
            result = true;
        }
        return result;
    }

    @RequestMapping(value = "/404")
    public String notFound(@RequestHeader("User-Agent") String userAgent) {
        if (isMobile(userAgent)) {
            return "/wesite/view/message";
        } else {
            return "/404";
        }
    }

}
